package net.sky.oaxz.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sky.oaxz.bean.XuzhaoNew;
import net.sky.oaxz.dao.XuzhaoNewDao;

public class UpdateServlet extends HttpServlet {

	private static final long serialVersionUID = 7269589136477222971L;

	/**
	 * Constructor of the object.
	 */
	public UpdateServlet() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;charset=UTF-8");
		doPost(request,response);
		
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;charset=UTF-8");
		request.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		int xzID1=Integer.parseInt(request.getParameter("xzID1"));

		int basnum=Integer.parseInt((request.getParameter("basnum")).trim());
		int winter=Integer.parseInt((request.getParameter("winter")).trim());
		int spring=Integer.parseInt(request.getParameter("spring").trim());
		XuzhaoNewDao xuzdao=new XuzhaoNewDao();
		XuzhaoNew xz2=new XuzhaoNew();
		xz2.setXzId(xzID1);
		xz2.setXzBasenum(basnum);
		xz2.setXzWinbase(winter);
		xz2.setXzSpring(spring);
		
		int num=xuzdao.updatexz(xz2);
		if(num > 0){
			out.print("<script type='text/javascript'>alert('修改成功！');location.replace('../xuzhaoNew/backstage/xzShowTeaNew.jsp');</script>");
		}else{
			out.print("<script type='text/javascript'>alert('修改失败！');history.go(-1);</script>");
		}
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}
